package speed2010.reformulacao.useful;
import speed2010.reformulacao.dao.User;
//Start the user session
public class ProfileSession {

	private static ProfileSession instance;
	
	private User user;
	private String ip;
	private String country;
	private boolean isLogged;
	
	static {
		ProfileSession.instance = new ProfileSession();
	}

	private ProfileSession() {
	}

	public static ProfileSession getInstance() {
		return ProfileSession.instance;
	}
	
	public void login(User u){
		this.user = u;
		this.ip = IpAddressLookupService.getInstance().getMyIP();
		this.country = CountryLookupService.getInstance().getCountryName(this.ip);
		this.isLogged = true;
	}
	
	public String getIpAddress() {
		return ip;
	}

	public void logout(){
		System.out.println("Logout user " + this.user.getLogin() + " - " + this.user.getName());
		this.user = null;
		this.isLogged = false;
	}

	public User getUser() {
		return user;
	}

	public String getCountryName() {
		return country;
	}
	
	public boolean isLogged() {
		return isLogged;
	}
}
